﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace ExamSharedClasses {
    /// <summary>
    /// (k) User ist die Basisklasse, um Benutzer abzubilden. Sie enthält
    /// eine eindeutige ID, Gruppenzugehörigkeit und E-Mail
    /// </summary>
    [Serializable()]
    public class User {
        public const string TABLENAME = "user";
        public const string USER_ID = "user_id";
        public const string USER_GROUP_ID = "user_group_id";
        public const string USER_EMAIL = "user_email";
        [XmlAttribute( "id" )]
        public int UserId { get; set; }
        public UserGroup UserGroup { get; set; }
        public string UserEmail { get; set; }

        public User() {
            this.UserId = -1;
            this.UserGroup = new UserGroup();
            this.UserEmail = "";
        }
        public User( string userEmail ) {
            this.UserId = -1;
            this.UserGroup = new UserGroup();
            this.UserEmail = userEmail;
        }

        public User( int userId, UserGroup userGroup, string userEmail ) {
            this.UserId = userId;
            this.UserGroup = userGroup;
            this.UserEmail = userEmail;
        }

        public string ToShortInformationString() {
            return UserEmail + ", " + UserGroup.GroupName;
        }
        public virtual string ToMoreDetailedString() {
            StringBuilder sb = new StringBuilder( );//"Benutzerinformationen: \n" );
            sb.Append( "User-Id: " + UserId.ToString() + '\n' );
            if ( UserGroup != null )
                sb.Append( "Gruppe: " + UserGroup.GroupName + '\n' );
            if ( UserEmail != null )
                sb.Append( "E-Mail-Adresse: " + UserEmail.ToString() + "\n\n" );
            return sb.ToString();
        }
        

        public override string ToString() {
            StringBuilder sb = new StringBuilder( );//"User: " );
            sb.Append( '\t' + UserId.ToString() + '\n' );
            if ( UserGroup != null )
                sb.Append( '\t' + UserGroup.ToString() );
            if ( UserEmail != null )
                sb.Append( '\t' + UserEmail.ToString() + '\n' );
            return sb.ToString();
        }
    }

}
